import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Ex02 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String strInput = "abc Axyz aDF.s";
		
		//chi chap nhan 1 ky thuoc [a-z]
		String regex = "[a-z]";
		String replace = "XYZ";
		
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(strInput);
		
		while(matcher.find()) {
			int s = matcher.start();
			int e = matcher.end();
			
			System.out.println("Matched: " + strInput.substring(s, e));
		}
		
		String output = matcher.replaceAll(replace);
		
		System.out.println("Output: " + output);
		
	}

}
